/*
 * StressTestThread.java
 *
 * Created on April 15, 2007, 10:37 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package catalogueclienttest1;

import usyd.comp5348.CatalogueRemote;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import usyd.comp5348.Catalogue;

/**
 *
 * @author david
 */
public class StressTestThread implements Runnable {
    
    private static final int THREAD_RUNS = 2;
    
    @EJB
    private static CatalogueRemote catalogueBean;
    
    private int id;
    
    /** Creates a new instance of StressTestThread */
    public StressTestThread(int id) throws Exception {
        Context initialContext = new InitialContext();
        catalogueBean = (CatalogueRemote) initialContext.lookup("Catalogue");
        this.id = id;
    }
    
    public void run() {
        for (int i=0; i<THREAD_RUNS; i++) {
            Catalogue a = new Catalogue();
            a.setCatalogueNumber("CATNUM(" + id + ":" + i + ")");
            a.setDirector("DIRECTOR(" + id + ":" + i + ")");
            a.setGenre("GENRE(" + id + ":" + i + ")");
            a.setPrice(id+i);
            a.setTitle("TITLE(" + id + ":" + i + ")");
            
            try {
                int j = catalogueBean.createVideo(a);
                System.out.println("Got back video: " + j);

                catalogueBean.deleteVideo(j);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
    
}
